package com.libcommon.ext

import android.graphics.Outline
import android.view.View
import android.view.ViewOutlineProvider
import android.widget.ImageView
import android.widget.TextView
import com.blankj.utilcode.util.SizeUtils
import com.blankj.utilcode.util.ViewUtils

fun View.clipToOutline(radius: Float) {
    outlineProvider = object : ViewOutlineProvider() {
        override fun getOutline(view: View?, outline: Outline?) {
            outline?.setRoundRect(0, 0, view?.width ?: 0, view?.height ?: 0, SizeUtils.dp2px(radius).toFloat())
        }
    }
    clipToOutline = true
}

fun TextView.adapterRtl() {
    this.textDirection = if (ViewUtils.isLayoutRtl()) View.TEXT_DIRECTION_RTL else View.TEXT_DIRECTION_LTR
}

fun ImageView.adapterRtl() {
    if (ViewUtils.isLayoutRtl()) {
        this.rotationY = 180f
    }
}
